<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>

    <link href="../css/login.css" rel="stylesheet" type="text/css"/>
    <style>
        #loginform{
            border:2px solid #eec6ce;
            border-radius: 10px;
        }
        .Hui-iconfont{
            color:#eec6ce;
        }
        #identity,#password{
            border-radius: 5px;
        }
    </style>

</head>
<body onkeydown="enterkey(event)">
    <div class="header">
        <div style="margin-top:10px;margin-left: 50px;font-size: 20px;color: aliceblue;">VIP注册系统</div>
    </div>

    <div class="loginWraper">
        <div id="loginform" class="loginBox">
            <form class="form form-horizontal" action="#">
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">用户名：</i></label>
                    <div class="formControls col-xs-8">
                        <input id="identity" name="identity" type="text" placeholder="请输入用户名"
                               class="input-text">
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-xs-3"><i class="Hui-iconfont">密码：</i></label>
                    <div class="formControls col-xs-8">
                        <input id="password" name="password" type="password" placeholder="密码" class="input-text size-L">
                    </div>
                </div>
                <div class="row cl">
                    <div class="col-xs-offset-3">
                        <input id="login" name="login" type="button" class="btn size-L"
                               value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;" onclick="login_submit()">
                        <input name="" type="reset" class="btn size-L" style="background-color: #e6e6e6;border-color: #e6e6e6;color: #333;"
                               value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script type="text/javascript" src="../lib/jquery.min.js"></script>
    <script type="text/javascript">
        function enterkey(et) {

            if (et.keyCode) {
                if (et.keyCode == 13)
                    $('#login').click();
            } else {
                if (et.which == 13)
                    $('#login').click();
            }

        }


        //登录处理
        function login_submit() {

            var identity = $("#identity").val();
            var password = $("#password").val();

            if (identity == null || identity == "") {
                alert("用户名不能为空！");
            } else if (password == null || password == "") {
                alert("密码不能为空！");
            } else {
                $.ajax({
                    type: 'POST',
                    url: '/user/login',
                    data: {
                        username: identity,
                        password: password
                    },
                    dataType: 'json',
                    success: function (data) {
                        var status = data.status;
                        var msg = data.msg;
                        if (status == 0) {
                            window.parent.location.href = "admin-index.html";
                        } else {
                            alert(msg)
                        }

                    },
                    error: function (data) {
                        console.log(data);
                        alert('显示异常，请刷新后重试');
                    },
                });

            }


        }


    </script>

</body>
</html>